import { version } from "punycode";

export const hasClass = (el, className) => {
  const reg = new RegExp('(^|\\s)' + className + '(\\s|$)')

  return reg.test(el.className)
}

export const addClass = (el, className) => {
  if (hasClass(el, className)) {
    return
  }

  const oldClassNames = el.className.split(' ')
  oldClassNames.push(className)
  el.className = oldClassNames.join(' ')
}

// js 加css前缀
const elementStyle = document.createElement('div').style

const vendor = (()=>{
  let transformNames = {
		webkit: 'webkitTransform',
		Moz: 'MozTransform',
		O: 'OTransform',
		ms: 'msTransform',
		standard: 'transform'
  }

  for(const key in transformNames){
    if(elementStyle[transformNames[key]]!==undefined){
      return key
    }
  }

  return false
})()

export const prefixStyle = style => {
  if (vendor === false){
    return false
  }

  if (vendor === 'standard'){
    return style
  }

  const styleStr = vendor + style.charAt(0).toUpperCase() + style.substring(1)

  return styleStr
}
